﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Text;
using System.Text.RegularExpressions;
using System.Data;
using System.Configuration;
using System.Net.Configuration;
using System.Security.Cryptography.X509Certificates;

/// <summary>
/// Summary description for SendEmail
/// </summary>
public class SendEmail
{
    SmtpClient sClient = new SmtpClient();

    string smtpServer = "smtp.gmail.com";
    string smtpMailFrom = "quocvuong1411@gmail.com";
    string smtpUser = "quocvuong1411";
    string smtpPassword = "voquocvuong14111987";
    int smtpPort = 587;
    string m_err=String.Empty;
    public String Err {
        get { return this.m_err; }
        set { this.m_err = value; }
    }

	public SendEmail()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public string SmtpServer
    {
        get { return smtpServer; }
        set { smtpServer = value; }
    }

    public string SmtpMailFrom
    {
        get { return smtpMailFrom; }
        set { smtpMailFrom = value; }
    }

    public string SmtpUser
    {
        set { smtpUser = value; }
    }

    public string SmtpPassword
    {
        set { smtpPassword = value; }
    }

    public Boolean Sendmail(string strMailTo, string strMailSubject, string strContent, bool bolIsHTMLFormat)
    {
        try
        {

            MailMessage objMail = new MailMessage();
            objMail.From = new MailAddress(smtpMailFrom);
            objMail.ReplyTo = new MailAddress(smtpMailFrom);
            objMail.To.Add(new MailAddress(strMailTo));
            objMail.Subject = strMailSubject;
            objMail.IsBodyHtml = bolIsHTMLFormat;
            objMail.Body = strContent;
            objMail.BodyEncoding = System.Text.Encoding.UTF8;
            sClient = new SmtpClient();
            sClient.EnableSsl = true;
            sClient.Send(objMail);

            return true;
        }
        catch (Exception err)
        {
            m_err = err.Message.ToString();
        }
        return false;
    }


}